package org.subject.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.subject.dao.ArticleMapper;
import org.subject.entity.Article;
import org.subject.entity.Page;
import org.subject.service.ArticleService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 通知消息接口实现类
 * Created by kai on 2017/5/14.
 */
@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;

    public int insertArticle(Article article) {
        return articleMapper.insert(article);
    }

    public List<Article> selectListArticle() {
        return articleMapper.selectListArticle();
    }

    public Article selectByPrimaryKey(Long articleId) {
        return articleMapper.selectByPrimaryKey(articleId);
    }

    public List<Article> queryArticleList(String title, int currentPage) {
        Map<String, Object> paramter = new HashMap<String, Object>();
        Article article = new Article();
        article.setArticleTitle(title);
        paramter.put("article", article);
        int count = queryArticleCount(title);
        Page page = new Page();
        page.setCurrentPage(currentPage);
        page.setTotalNumber(count);
        paramter.put("page", page);
        return articleMapper.queryArticleList(paramter);
    }

    public int queryArticleCount(String title) {
        Map<String, Object> paramter = new HashMap<String, Object>();
        Article article = new Article();
        article.setArticleTitle(title);
        paramter.put("article", article);
        return articleMapper.queryArticleCount(paramter);
    }

    public int deleteArticleById(String articleId) {
        Long id = Long.valueOf(articleId);
        return articleMapper.deleteByPrimaryKey(id);
    }
}
